package com.cn.lp.converter.demo.converter;


import com.cn.lp.converter.BeanConverter;
import com.cn.lp.converter.MergeResult;
import com.cn.lp.converter.annotation.ConverterMapper;
import com.cn.lp.converter.annotation.ConverterMapping;
import com.cn.lp.converter.annotation.FieldNameFilter;
import com.cn.lp.converter.annotation.ReNameField;
import lombok.Data;
import org.springframework.web.bind.annotation.Mapping;

import java.util.List;
import java.util.Map;
import java.util.Set;

@ConverterMapper(ignoreEmpty = true, ignoreGenericType = true,
    fieldNameFilter = @FieldNameFilter(assignIgnoreRegexFieldName = "ignore*"),
    reNameField = @ReNameField(sourceName = "oldName", targetName = "newName"))
public interface TestMappingFieldConverter extends BeanConverter<TestMappingFieldConverter.EntityA, TestMappingFieldConverter.EntityB> {

    @Data
    class EntityA {

        private Set<String> listData;

        private Map<String, Integer> mapData;

        private int age;

        private String oldName;

        private String emptyData;

        private String ignoreFiled;

    }

    @Data
    class EntityB {

        private List<String> listData;

        private Map mapData;

        private Long age;

        private String newName;

        private String emptyData;

        private String ignoreFiled;
    }

    @Override
    @ConverterMapping(ignoreEmpty = false, fieldNameFilter = @FieldNameFilter(assignFieldName = "emptyData", assignRegexFieldName = "ignore*"))
    MergeResult<EntityB> mergeTo(EntityA source, EntityB target);

}